package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.util.DateFormatUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName : UntieStartTimeHandler
 * @Description : 解绑开始时间
 * @Author : chen.cheng110
 * @Date : 2020/12/19 22:39
 */
@Service
public class UntieStartTimeHandler extends AbstractAttrHandler {
    @Resource
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void init(CommonAttrVO commonAttr) {

    }

    @Override
    public DataResult<Boolean> apply(String sceneInstId, String fieldName, String value, String valueDesc) {
        KiteAttr untieEndTime = querySceneInstService.getCommonAttr(sceneInstId, "ORD10190");
        String endTime = untieEndTime.getValue();
        if (KiteStringUtils.isEmpty(value) || KiteStringUtils.isEmpty(endTime)) {
            return super.apply(sceneInstId, fieldName, value, valueDesc);
        }
        int num = DateFormatUtils.compareDate(value, endTime, DateFormatUtils.DATE_TIME_FORMAT);
        if (num > 0) {
            ErrorConsts.BUSI_COMMON_ERROR.throwOut("解绑开始时间不能大于解绑结束时间，请核实后再操作！");
        }
        return super.apply(sceneInstId, fieldName, value, valueDesc);
    }
}
